<?php
$this->breadcrumbs=array(
	UserModule::t('Users')=>array('admin'),
	$model->username,
);
?>

<?php 
$userid = Yii::app()->user->id;
$user = User::model()->find('id=:ID ',array(':ID'=>$userid));
$unit_level = $user->unit_level;
?>

<div id="page-header">
	<h1><?php echo UserModule::t('查看用户').' "'.$model->username.'"'; ?></h1>
    <div id="page-options">
	<?php $this->renderPartial('_menu',array(
    'model'=>$model,
	'unit_level' => $unit_level,
    )); ?>
    </div>
</div>

<?php 

$unit = User::model()->getUnit($model->id);
/*
//		echo CHtml::activeLabelEx($model,'unit_id');	
/*		$unit = '超级管理员';	
		switch($model->unit_level){
			case 1:
//				echo '<label>'.MtsysProvince::model()->findByPk($model->unit_id)->PROVINCE_NAME.'</label>';
				$unit = MtsysProvince::model()->findByPk($model->unit_id)->PROVINCE_NAME;
				break;
			case 2:
				$city =  MtsysCity::model()->findByPk($model->unit_id);
				$sheng = MtsysProvince::model()->find('PROVINCE_ID=:PID',array(
					':PID' => $city->PROVINCE_ID
));
//				echo '<label>'.$sheng->PROVINCE_NAME.'&nbsp;&nbsp;-&nbsp;&nbsp;'.$city->CITY_NAME.'</label>';
				$unit = $sheng->PROVINCE_NAME.'&nbsp;&nbsp;-&nbsp;&nbsp;'.$city->CITY_NAME;
				break;
			case 3:
				$county =  MtsysCounty::model()->findByPk($model->unit_id);
				$city = MtsysCity::model()->find('CITY_ID=:CID',array(
					':CID' => $county->CITY_ID
));
				$sheng = MtsysProvince::model()->find('PROVINCE_ID=:PID',array(
					':PID' => $city->PROVINCE_ID
));
//				echo '<label>'.$sheng->PROVINCE_NAME.'&nbsp;&nbsp;-&nbsp;&nbsp;'.$city->CITY_NAME.'&nbsp;&nbsp;-&nbsp;&nbsp;'.$county->COUNTY_NAME.'</label>';
				$unit = $sheng->PROVINCE_NAME.'&nbsp;&nbsp;-&nbsp;&nbsp;'.$city->CITY_NAME.'&nbsp;&nbsp;-&nbsp;&nbsp;'.$county->COUNTY_NAME;
				break;
			case 4:
				$base = MtsysBase::model()->findByPk($model->unit_id);
			    $county =  MtsysCounty::model()->findByPk($base->COUNTY_ID);
				$city = MtsysCity::model()->find('CITY_ID=:CID',array(
					':CID' => $base->CITY_ID
));
				$sheng = MtsysProvince::model()->find('PROVINCE_ID=:PID',array(
					':PID' => $base->PROVINCE_ID
));
//				echo '<label>'.$sheng->PROVINCE_NAME.'&nbsp;&nbsp;-&nbsp;&nbsp;'.$city->CITY_NAME.'&nbsp;&nbsp;-&nbsp;&nbsp;'.$county->COUNTY_NAME.'&nbsp;&nbsp;-&nbsp;&nbsp;'.$base->BASE_NAME.'</label>';
				$unit = $sheng->PROVINCE_NAME.'&nbsp;&nbsp;-&nbsp;&nbsp;'.$city->CITY_NAME.'&nbsp;&nbsp;-&nbsp;&nbsp;'.$county->COUNTY_NAME.'&nbsp;&nbsp;-&nbsp;&nbsp;'.$base->BASE_NAME;
				break;
		}*/
		
/*		$role = "超级管理员";
		$criteria=new CDbCriteria;
		$criteria->select='itemname';
		$criteria->condition='userid=:userid';
		$criteria->params=array(':userid'=>$model->id);
		$rolename = AssignmentForm::model()->find($criteria);
		
		$criteria=new CDbCriteria;
		$criteria->select='description';
		$criteria->condition='name=:rolename';
		$criteria->params=array(':rolename'=>$rolename);
		$roledesc = AuthItemForm::model()->find($criteria);	
*/	 
?>


<?php 
	$attributes = array(
//		'id',
		'username',
	);
	
	$profileFields=ProfileField::model()->forOwner()->sort()->findAll();
	if ($profileFields) {
		foreach($profileFields as $field) {
			array_push($attributes,array(
					'label' => UserModule::t($field->title),
					'name' => $field->varname,
					'type'=>'raw',
					'value' => (($field->widgetView($model->profile))?$field->widgetView($model->profile):(($field->range)?Profile::range($field->range,$model->profile->getAttribute($field->varname)):$model->profile->getAttribute($field->varname))),
				));
		}
	}
	
	array_push($attributes,
//		'password',
		'surname',
		'telephone',
		'email',
		
//		'activkey',
//		'unit_level',
/*		array(
				'name' => 'unit_level',
				'type' => 'raw',
				'value' => $roledesc,
		),*/
		array(
			'name' => 'unit_id',
			'type' => 'raw',
			'value' => $unit,
//			'value' => 'User::model()->getUnit($model->id)',
		),
		array(
			'name' => 'createtime',
			'value' => date("d.m.Y H:i:s",$model->createtime),
		),
		array(
			'name' => 'lastvisit',
			'value' => (($model->lastvisit)?date("d.m.Y H:i:s",$model->lastvisit):UserModule::t("Not visited")),
		)

	);
	
	$this->widget('zii.widgets.CDetailView', array(
		'data'=>$model,
		'attributes'=>$attributes,
	));
	

?>
